import { createContext } from "react";

// 用户角色类型定义
export type UserRole = 'student' | 'admin' | 'merchant';

// 用户信息接口
export interface UserInfo {
  id: string;
  username: string;
  role: UserRole;
  avatar?: string;
  campus?: string;
}

// 认证上下文接口
interface AuthContextType {
  isAuthenticated: boolean;
  userInfo: UserInfo | null;
  setIsAuthenticated: (value: boolean) => void;
  setUserInfo: (userInfo: UserInfo | null) => void;
  logout: () => void;
  login: (username: string, password: string) => Promise<boolean>;
  register: (username: string, password: string, role: UserRole) => Promise<boolean>;
}

// 默认值
export const AuthContext = createContext<AuthContextType>({
  isAuthenticated: false,
  userInfo: null,
  setIsAuthenticated: () => {},
  setUserInfo: () => {},
  logout: () => {},
  login: async () => false,
  register: async () => false,
});